From: Akseli Lahtinen Date: Tue, 13 May 2025 10:01:07 +0000 (+0300) Subject: [PATCH] Avoid unnecessary sequencing jobs in PreviewGenerator X-Git-Tag: archive/raspbian/6.13.0-6+rpi1^2~3 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=115c76e23f6c4ec0c1413b8ea9bf537a7879bbc6;p=kf6-kio.git [PATCH] Avoid unnecessary sequencing jobs in PreviewGenerator Currently we keep constantly asking if the current item has sequences support or not. By sequences we mean things like hovering mouse over a folder thumbnail and it goes through the files in it. This MR will always run for the first sequence (the initial thumbnail) but for the rest, then toggles a flag for the node with Qt::DecorationPropertyRole. If the propertyrole is false, it skips any further updates to avoid any unnecessary previewjob runs. Gbp-Pq: Name upstream_c747fa0f_Avoid-unnecessary-sequencing-jobs-in-PreviewGenerator.patch --- diff --git a/src/filewidgets/kfilepreviewgenerator.cpp b/src/filewidgets/kfilepreviewgenerator.cpp index 481d324..3b5dc32 100644 --- a/src/filewidgets/kfilepreviewgenerator.cpp +++ b/src/filewidgets/kfilepreviewgenerator.cpp @@ -1015,6 +1015,11 @@ void KFilePreviewGeneratorPrivate::startPreviewJob(const KFileItemList &items, i q->connect(job, &KIO::PreviewJob::gotPreview, q, [this, job](const KFileItem &item, const QPixmap &pixmap) { addToPreviewQueue(item, pixmap, job); + m_dirModel->setData(m_dirModel->indexForItem(item), job->handlesSequences(), KDirModel::HandleSequencesRole); + }); + + q->connect(job, &KIO::PreviewJob::failed, q, [this, job](const KFileItem &item) { + m_dirModel->setData(m_dirModel->indexForItem(item), job->handlesSequences(), KDirModel::HandleSequencesRole); }); q->connect(job, &KIO::PreviewJob::finished, q, [this, job]() { diff --git a/src/gui/previewjob.cpp b/src/gui/previewjob.cpp index 0841189..65902ea 100644 --- a/src/gui/previewjob.cpp +++ b/src/gui/previewjob.cpp @@ -395,6 +395,8 @@ void PreviewJobPrivate::startPreview() item.standardThumbnailer = plugin.description() == QStringLiteral("standardthumbnailer"); item.plugin = plugin; items.push_back(item); + bool handlesSequencesValue = item.plugin.value(QStringLiteral("HandleSequences"), false); + thumbnailWorkerMetaData.insert(QStringLiteral("handlesSequences"), QString::number(handlesSequencesValue)); if (!bNeedCache && bSave && plugin.value(QStringLiteral("CacheThumbnail"), true)) { const QUrl url = fileItem.targetUrl(); diff --git a/src/widgets/delegateanimationhandler.cpp b/src/widgets/delegateanimationhandler.cpp index 9d8f81b..741416a 100644 --- a/src/widgets/delegateanimationhandler.cpp +++ b/src/widgets/delegateanimationhandler.cpp @@ -200,8 +200,11 @@ void DelegateAnimationHandler::sequenceTimerTimeout() KDirModel *dirModel = dynamic_cast(model); if (dirModel) { // qDebug() << "requesting" << currentSequenceIndex; - dirModel->requestSequenceIcon(index, currentSequenceIndex); - iconSequenceTimer.start(); // Some upper-bound interval is needed, in case items are not generated + // Only request sequence icons for items that have them + if (dirModel->data(index, KDirModel::HandleSequencesRole).toBool()) { + dirModel->requestSequenceIcon(index, currentSequenceIndex); + iconSequenceTimer.start(); // Some upper-bound interval is needed, in case items are not generated + } } } diff --git a/src/widgets/kdirmodel.cpp b/src/widgets/kdirmodel.cpp index 1aff865..da479e5 100644 --- a/src/widgets/kdirmodel.cpp +++ b/src/widgets/kdirmodel.cpp @@ -101,10 +101,21 @@ public: m_preview = icn; } + bool previewHandlesSequences() + { + return m_previewHandlesSequences; + } + + void setPreviewHandlesSequences(bool handlesSequences) + { + m_previewHandlesSequences = handlesSequences; + } + private: KFileItem m_item; KDirModelDirNode *const m_parent; QIcon m_preview; + bool m_previewHandlesSequences = true; // First sequence is always allowed }; // Specialization for directory nodes @@ -915,6 +926,11 @@ QVariant KDirModel::data(const QModelIndex &index, int role) const } } break; + case HandleSequencesRole: + if (index.column() == Name) { + return node->previewHandlesSequences(); + } + break; case Qt::TextAlignmentRole: if (index.column() == Size) { // use a right alignment for L2R and R2L languages @@ -1034,6 +1050,14 @@ bool KDirModel::setData(const QModelIndex &index, const QVariant &value, int rol return true; } break; + case HandleSequencesRole: + if (index.column() == Name) { + KDirModelNode *node = static_cast(index.internalPointer()); + Q_ASSERT(node); + node->setPreviewHandlesSequences(value.toBool()); + return true; + } + break; default: break; } diff --git a/src/widgets/kdirmodel.h b/src/widgets/kdirmodel.h index e287674..118a2c4 100644 --- a/src/widgets/kdirmodel.h +++ b/src/widgets/kdirmodel.h @@ -160,6 +160,7 @@ public: FileItemRole = 0x07A263FF, ///< returns the KFileItem for a given index. roleName is "fileItem". ChildCountRole = 0x2C4D0A40, ///< returns the number of items in a directory, or ChildCountUnknown. roleName is "childCount". HasJobRole = 0x01E555A5, ///< returns whether or not there is a job on an item (file/directory). roleName is "hasJob". + HandleSequencesRole = 0x1E642272, }; /**